using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Edge.Common.Utils;

namespace Edge.Common.Web.Features
{
     [
    DefaultProperty(""),
    ParseChildren(false),
    ToolboxData("<{0}:DiceButton runat=\"server\"/>")
    ]
    public class DiceButton : System.Web.UI.WebControls.Button
    {
        public DiceButton()
        {
        
        }

        private bool throwDone;

        [Browsable(false)]
        public bool ThrowDone
        {
            get { return throwDone; }
        }

        protected override void OnInit(EventArgs e)
        {
//
//            if (StringUtils.IsBlankOrNull(GridID))
//                throw new ArgumentException("GridID must be non empty");
//            grid = this.NamingContainer.FindControl(gridID) as GridView;
//
//            if (grid == null)
//                throw new InvalidOperationException("GridID must be name of GridView control");
//
//            grid.DataBinding += new EventHandler(SetupSelectHandler);
//            grid.RowDataBound += new GridViewRowEventHandler(Grid_OnRowDataBound);
//            //            this.PageIndex.Load += new EventHandler(SetupHandler);

            base.OnInit(e);
        }

         protected override void OnPreRender(System.EventArgs e)
        {
//            if (SelectedValueDeleted && !IsLabel)
//            {
//                if (this.Attributes["onchange"] == null) this.Attributes["onchange"] = "";
//                if (this.Attributes["onchange"].IndexOf(FunctionName) < 0)
//                    this.Attributes["onchange"] = this.Attributes["onchange"] + " " + FunctionName + "; ";
//            }
            base.OnPreRender(e);
        }

        /// <summary> 
        /// display text box or label
        /// </summary>
        protected override void Render(HtmlTextWriter output)
        {

//            if (!IsLabel)
//            {
//                base.Render(output);
//            }
//            else
//            {
//
//                Label lb = new Label();
//                lb.ID = this.ClientID;
//                lb.Text = GetLabelText();
//                lb.ToolTip = ToolTip;
//                lb.RenderControl(output);
//            }
//
//            if (!SelectedValueDeleted) return;
//
//            Label lb2 = new Label();
//            lb2.ID = DeletedMessageId;
//            lb2.CssClass = "validator";
//            lb2.Text = " was deleted";
//            lb2.RenderControl(output);
//
//            if (IsLabel) return;
//
//            string scrM = " <script language=\"javascript\" type=\"text/javascript\">function {0}{{ var ob = document.getElementById('{1}'); var mes = document.getElementById('{3}'); if (ob.options[ob.selectedIndex].value == {2}) mes.style.display = ''; else mes.style.display = 'none'; }}</script>";
//
//            output.Write(string.Format(scrM, FunctionName, ClientID, SelectedValue, DeletedMessageId));
            base.Render(output);

        }

        [Browsable(true)]
        public bool IsLabel
        {
            get
            {
                object state = ViewState["IsLabel"];
                return state != null ? (bool)state : false;
            }
            set
            {
                ViewState["IsLabel"] = value;
            }
        }
    }
}
